package com.wordpress.fatecode.model;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.wordpress.fatecode.entity.Agenda;
import com.wordpress.fatecode.jdbc.Conexao;

public class AgendaDAO implements DAO<Agenda>{
	private Connection connetion;
	private PreparedStatement stmt;
	private ResultSet result;
	private static Map<Long, Agenda> agendas = new HashMap<>();
	
	
	@Override
	public void salvar(Agenda agenda) {
		connetion = new Conexao().getConnection();
		try {
			stmt = connetion.prepareStatement("");
			stmt.setString(1, "");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void alterar(Agenda agenda) {
		connetion = new Conexao().getConnection();
		try {
			stmt = connetion.prepareStatement("");
			stmt.setString(1, "");
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void excluir(long id) {
		Agenda agenda = agendas.remove(id);
		System.out.println("Agenda removida.: " + agenda.toString());
	}

	@Override
	public Agenda buscar(long id) {
		Agenda agenda = agendas.get(id);
		System.out.println("Agenda localizada.: " + agenda.toString());
		return agenda;
	}

	@Override
	public List<Agenda> listar() {
		connetion = new Conexao().getConnection();
		try {
			stmt = connetion.prepareStatement("");
			result = stmt.executeQuery();
			
			while (result.next()) {
				
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		List<Agenda> listaAgenda = new ArrayList<>();
		
		
		return listaAgenda;
	}

	@Override
	public void cadastrar(Agenda agenda) {
		if (agenda.getAgendamento() > 0) {
			this.alterar(agenda);
		} else {
			this.salvar(agenda);
		}		
	}

	@Override
	public void close() {
		try {
			if (result != null) 
				result.close();
			
			if (stmt != null)
				stmt.close();
			
			if (connetion != null)
				connetion.close();
			
		} catch (SQLException ex) {
			ex.printStackTrace();
		}
		
	}

}
